package androidx.lifecycle.ktx

import androidx.lifecycle.Lifecycle

/**
 * 生命周期扩展的共享实现
 */
fun Lifecycle.isActive() = currentState.isAtLeast(Lifecycle.State.STARTED)

/**
 * 安全地执行生命周期相关操作
 */
fun <T> Lifecycle.runWithLifecycle(block: () -> T): T? {
    if (!isActive()) return null
    return block()
}